package sm.pzavoli.mercato.model.db;

import java.util.Iterator;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteQueryBuilder;
import android.util.Log;
import sm.pzavoli.mercato.MercatoDBOpenHelper;

public class TickerStoricoDAO {

	public static Cursor query(Context context, MercatoDBOpenHelper db, String symbol, 
			String orderby) {
		try {
	        if (db == null) {
	            Log.e("TicketStoricoDAO", "db is null");
	            return null;
	        }
	        SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
	        qb.setTables(MercatoDBOpenHelper.STORICO_TABLE);
	        String selection = "";
	        if ( symbol != null && symbol.length() > 0 ) {
	        	selection = " symbol = '"+symbol.trim()+"'";
	        }
	        Cursor c = qb.query(db.getReadableDatabase(),
	                null,
	                selection, null,
	                null, null, orderby);
	        return c;
		} catch(Exception e) {
			e.printStackTrace();
			Log.e("TicketStoricoDAO", "Errore in apertura cursore");
			return null;
		}
	}
}
